package com.example.tellwin.home.adpater;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.tellwin.R;
import com.example.tellwin.home.bean.KnowledgeVpBean;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class KnowledgeVpAdapter extends RecyclerView.Adapter<KnowledgeVpAdapter.KnowledgeVpViewHolder> {

    List<KnowledgeVpBean> beans = new ArrayList<>();

    public void setBeans(List<KnowledgeVpBean> beans) {
        this.beans = beans;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public KnowledgeVpViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new KnowledgeVpViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_view_pager, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull KnowledgeVpViewHolder holder, int position) {
        KnowledgeVpBean bean = beans.get(position);
        holder.itemHomeVpTitleTv.setText(bean.getTitle());
        holder.itemHomeVpContentTv.setText(bean.getContent());
        Log.e("KnowledgeVpAdapter", "" + position);
        holder.itemHomeVpLikeIv.setOnClickListener(view -> {

        });
        holder.itemHomeVpShareIv.setOnClickListener(view -> {

        });
    }

    @Override
    public int getItemCount() {
        return beans.size();
    }

    class KnowledgeVpViewHolder extends RecyclerView.ViewHolder {
        TextView itemHomeVpTitleTv;
        TextView itemHomeVpContentTv;
        ImageView itemHomeVpShareIv;
        ImageView itemHomeVpLikeIv;

        public KnowledgeVpViewHolder(@NonNull View itemView) {
            super(itemView);
            itemHomeVpTitleTv = (TextView) itemView.findViewById(R.id.item_home_vp_title_tv);
            itemHomeVpContentTv = (TextView) itemView.findViewById(R.id.item_home_vp_content_tv);
            itemHomeVpShareIv = (ImageView) itemView.findViewById(R.id.item_home_vp_share_iv);
            itemHomeVpLikeIv = (ImageView) itemView.findViewById(R.id.item_home_vp_like_iv);
        }
    }
}
